import { CHANGE_SONG_URL, CHANGE_CURRENT_MUSIC_INFO, CHANGE_SONG_INOF } from '../mutaion-types'
import { getMusicUrl, getSonges } from '@/api'
const mp3 = {
  state: {
    musicIdUrl: '',
    currentMusicInfo: {},
    mp3Info: {}
  },
  actions: {
    getaaa ({ commit }, data) {
      // 通过点击事件获取id == data
      console.log(data, 'id')
      getMusicUrl({ id: data }).then(res => {
        const { url } = res.data.data[0]
        // console.log('actions', url)
        // console.log('数据', res)
        commit(CHANGE_SONG_URL, { url })
        commit(CHANGE_CURRENT_MUSIC_INFO, { data: res.data.data[0] })
      })
      // 获取歌名和图片
      getSonges({ ids: data }).then(res => {
        const { al } = res.data.songs[0]
        commit(CHANGE_SONG_INOF, { al })
      })
    }
  },
  mutations: {
    [CHANGE_SONG_URL] (state, paylord) {
      // console.log('我是数据', paylord)
      state.musicIdUrl = paylord.url
      // console.log(paylord.url)
    },
    [CHANGE_CURRENT_MUSIC_INFO] (state, paylord) {
      state.currentMusicInfo = paylord
      // console.log('数据对象', paylord)
    },
    [CHANGE_SONG_INOF] (state, paylord) {
      // console.log(paylord)
      state.mp3Info = paylord.al
      // console.log('数据对象', paylord)
    }
  }
}
export default mp3
